/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.utils;

import java.util.ArrayList;
import java.util.List;

import com.siro.pm.I18nManager;
import com.siro.pm.model.Developer;
import com.siro.pm.model.Project;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.AbstractSelect.Filtering;
import com.vaadin.ui.ComboBox;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since DeveloperBrowser.java v1.0
 */
public class DeveloperBrowser {

	public static void configDeveloperBrowser(final ComboBox developerBrowser,
			Project project) {
		List<Developer> developers = null;
		if (project == null) {
			developers = Developer.getAllDevelopers();
		} else {
			developers = project.getDevelopers();
		}
		if (developers == null) {
			developers = new ArrayList<Developer>();
		}
		// developerBrowser.setContainerDataSource(DeveloperProvider
		// .getDevelopersData(developers));
		for (Developer developer : developers) {
			developerBrowser.addItem(developer);
			developerBrowser.setItemCaption(developer, developer.getName());
		}
		developerBrowser
				.setInputPrompt(I18nManager.getMessage("button.browse"));
		developerBrowser.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
		developerBrowser.setImmediate(true);
		developerBrowser.addListener(new ValueChangeListener() {
			private static final long serialVersionUID = 1L;

			public void valueChange(ValueChangeEvent event) {
				Object value = event.getProperty().getValue();
				developerBrowser.setValue(value);
			}
		});
	}
}
